<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>优惠券</title>
    <link rel="stylesheet" type="text/css" href="../../css/mui.min.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/own.css"/>
	<script type="text/javascript" src="../../js/mui.min.js" ></script>
	<script type="text/javascript" src="../../js/common.js"></script>
    <script>
    	mui.init({
//		    subpages:[{
//		      url:'../commonback.html',
//		      id:'common.html',
//		      styles:{
//		        top:'0px',//mui标题栏默认高度为45px；
//		      }
//		    }]
			swipeBack: false
		  });    
		 
		(function($) {
			$('.mui-scroll-wrapper').scroll({
				indicators: true //是否显示滚动条
			});
			var sliderSegmentedControl = document.getElementById('sliderSegmentedControl');				
		})(mui);	 
		    
		  var c_list=null;
		  mui.plusReady(function(){
		  	//初始化监听头部和底部事件
			tzdr.init.initHearListener();
  				
		  	//获取优惠券信息
		  	getCoupons();
		   	
		  });
		  
		  
		  function useCoupons(id){
		  	var paramUrl={
				url:"../login/login.html"
			}
		  	mui.app_request("/user/coupon/employ",{
		  		"id":id
		  	},function(result){
		  		mui.toast("红包领取成功!");
		  		location.reload(true);
		  		return;
		  	},function(result){
		  		if(result.code==2){
		  			mui.toast("未找到该数据");
		  			return;
		  		}else if(result.code==3){
		  			mui.toast("该红包已过期");
		  			return;
		  		}else if(result.code==4){
		  			mui.toast("该红包已使用");
		  			return;
		  		}else if(result.code==5){
		  			mui.toast("非法类型数据");
		  			return;
		  		}else if(result.code==6){
		  			mui.toast("编号不能为空");
		  			return;
		  		}else{
		  			mui.toast("系统繁忙，请稍后再试！");
		  			return;
		  		}
		  		
		  	},paramUrl)
		  };
		  
		    
		  function	getCoupons(){
		  	 	var paramUrl={
					url:"../login/login.html"
				}
		  	mui.app_request("/user/coupon/list",{},function(result){
		  		if(!mui.isnull(result.data.couponList)){ 
		  			c_list=result.data.couponList;
		  			mui.each(c_list,function(i){
		  					//动态创建子元素
		  					nowCoupon(c_list[i]);
		  				
		  			});
		  			
		  		//绑定监听
		  		mui(".mui-table-view").on('tap','a',function(){
					  //获取id
					  var id = this.getAttribute("id");
					  if("未使用"==this.innerHTML||"已使用"==this.innerHTML||"已过期"==this.innerHTML){
					  	return;
					  }
					  //使用现金红包
					  useCoupons(id);
					});
		  	
		  			
		  		}else{
		  			document.getElementById("no_list").style.display="block";
		  		}
		  		
		  	},function(result){
		  		mui.toast(result.message);
		  		return;
		  	},paramUrl); 
		  };
		  
		  	
		   function nowCoupon(couponList){
		 	var ul_list=document.getElementById("ul_list");
		 	
		 	var ul_one=document.createElement("ul");
		 	ul_one.setAttribute("class","mui-table-view");
		 	var li=document.createElement("li");
		 	li.setAttribute("class","mui-table-view-cell");
		 	
		 	var div=document.createElement("div");
		 	div.setAttribute("class","acp_info");
		 	
		 	var h4=document.createElement("h4");
		 	var h3=document.createElement("h3");
		 	
		 	var a=document.createElement("a");
		 	var b=document.createElement("b");
		 	if(couponList.status==2){
		 		a.innerHTML="未使用";
		 	}else if(couponList.status==4){
		 		b.innerHTML="已过期";
		 		li.setAttribute("class","mui-table-view-cell apc_no");
		 	}else{
		 		b.innerHTML="已使用";
		 		li.setAttribute("class","mui-table-view-cell apc_no");
		 	}
		 	a.setAttribute("id",couponList.id);
		 	switch(couponList.type){
		 		case 1:
		 		h3.innerHTML="现金红包";
		 		h4.innerHTML="<img src='../../images/acp_01.png'><b>¥</b><span>"+couponList.money+"元</span>";
		 		if(couponList.status==2){
		 			a.innerHTML="点击领取";
		 		}else if(couponList.status==4||couponList.status==3){
		 		h4.innerHTML="<img src='../../images/acp_04.gif'><b>¥</b><span>"+couponList.money+"元</span>";
		 		}
		 	
		 		break;
		 		case 2:
		 		h3.innerHTML="代金券";
		 		h4.innerHTML="<img src='../../images/acp_02.png'><b>¥</b><span>"+couponList.money+"元</span>";
		 		if(couponList.status==4||couponList.status==3){
		 		h4.innerHTML="<img src='../../images/acp_05.gif'><b>¥</b><span>"+couponList.money+"元</span>";
		 		}
		 		break;
		 		case 3:
		 		h3.innerHTML="折扣券";  
		 		h4.innerHTML="<img src='../../images/acp_03.gif'><b>¥</b><span>"+couponList.money+"折</span>";
		 		if(couponList.status==4||couponList.status==3){
		 		h4.innerHTML="<img src='../../images/acp_06.gif'><b>¥</b><span>"+couponList.money+"折</span>";	
		 		}
		 		break;
		 		default:
		 		break;
		 	}
		 	
		 	var p=document.createElement("p");
		 	p.innerHTML="获得日期：<span>"+tzdr.dateUtil.getFormatDataByLong(couponList.grantTime,'yyyy-MM-dd hh:mm')+"</span><br>到期日期：<span>"+tzdr.dateUtil.getFormatDataByLong(couponList.deadline,'yyyy-MM-dd hh:mm')+"</span><br>来源：<span>"+couponList.name+"</span>";
		 	
		 	if(couponList.status==4||couponList.status==3){
		 		h3.appendChild(b);
		 	}else{
		 		h3.appendChild(a);
		 	}
		 	div.appendChild(h4); 
		 	div.appendChild(p);
		 	
		 	li.appendChild(h3);
		 	li.appendChild(div);
		 	ul_one.appendChild(li);
		 	ul_list.appendChild(ul_one);
		 };
		  
		  
		  
		
		  
		  
		  
    </script>
	<style>
		.mui-control-content {
			background-color: white;
			min-height: 600px;  
		}
		.mui-control-content .mui-loading {
			margin-top: 50px;
		}
		
	</style>
</head>
<body>			
	<header class="mui-bar mui-bar-nav own-topbg">
		<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left" id="back"><i>返回</i></a>
		<h1 class="mui-title">我的优惠券</h1>		
		<a href="javascript:void(0)" class="top-tel" id="telBtn">客服热线</a>
	</header>
	<!--<nav class="navlist">
		<a href="javascript:void(0);" id="product">
			<span class="mui-icon mui-icon-list"></span>
			<span class="mui-tab-label">产品</span>
		</a>
		<a class="" href="javascript:void(0);"  id="scheme">
			<span class="mui-icon mui-icon-compose"></span>
			<span class="mui-tab-label">方案</span>
		</a>
		<a  class="navon"  id="account" href="javascript:void(0);">
			<span class="mui-icon mui-icon-contact mui-icon-icon-contact-filled"></span>
			<span class="mui-tab-label" >账户</span>
		</a>
	</nav>-->
	<div class="mui-content ac_charge">
		<div id="slider" class="mui-slider">
			<div class="mui-slider-group ac_coupon">
				<div style="display: none;" id="no_list">
					<img src="../../images/list_02.png" />
						<span>您还没有优惠券！</span>
				</div>
				<div id="ul_list"></div>
				<!--<ul class="mui-table-view">  
					
				</ul>-->
			</div>
		</div>
	</div>
	
</body>
</html>